#define WHUSER_EXPORTS 

#include "OH-DLL.h"
#include <windows.h>
#include <bitset>

using namespace std;
#include "OHAIManager.h"
#include "ezlogger_headers.hpp"
#include "pokersleuth.h"

#include "OH-general.h"
#include "preflop.h"
#include "flop.h"
#include "turn.h"
#include "river.h"
#include "sfGlobals.h"
#include "HoldemState.h"
#include "iPlayerInfo.h"
#include "iPlayerAI.h"
#include "IcmEVCalculator.h"
#include "DataCont.h"

HoldemState StateCopyGL;

OHAIManager managerAI;




double process_query(const char* pquery){

	if(pquery==NULL)
		return 0;
	//example
	//EZLOGGERSTREAM << "process query: " << pquery<< std::endl;
	if(strcmp(pquery,"dll$decision")==0)
		return sfGlobals::GetSingleton()->decision;

	return 0;

}

double process_state(holdem_state* pstate){	
	
	int nextPose=-1;
	//EZLOGGERSTREAM << "process state" << std::endl;
	if(pstate!=NULL)
      sfGlobals::GetSingleton()->m_holdem_state[ (++(sfGlobals::GetSingleton()->m_ndx))&0xff ] = *pstate;

	//resetting decision
	sfGlobals::GetSingleton()->decision = 0;
	sfGlobals::GetSingleton()->ismyturn=(bool)gws("ismyturn");
	//Calculate Current StackEV

	//--------------------------
	

	//calculating decision if it's my turn

	if(sfGlobals::GetSingleton()->ismyturn)
	{			
		//managerAI.GetMStack()
		
	}
	return 0;
}
///////////////////////////////////////////////////// 
//WINHOLDEM RUNTIME ENTRY POINT 
///////////////////////////////////////////////////// 
WHUSER_API double process_message(const char* pmessage, const void* param){
	
	if(pmessage==NULL){
		return 0;
	}
	if(param==NULL){
		return 0;
	}
	// char buf[16];
	 
	//EZLOGGERSTREAM << pmessage << std::endl;
	if(strcmp(pmessage,"state")==0){
		
		return process_state( (holdem_state*)param );
	}
	if(strcmp(pmessage,"phl1k")==0){   
		sfGlobals::GetSingleton()->m_phl1k = (phl1k_t)param;
		return 0;
	}
	if(strcmp(pmessage,"prw1326")==0){	
		sfGlobals::GetSingleton()->prw1326 = (pp13)param;
		return 0;
	}
	if(strcmp(pmessage,"query")==0){ 
		return process_query((const char*)param);
	}
	if(strcmp(pmessage,"pfgws")==0){
		sfGlobals::GetSingleton()->m_pget_winholdem_symbol = (pfgws_t)param;
		return 0;
	}
	return 0;
}
///////////////////////////////// 
//DLLMAIN 
///////////////////////////////// 
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){

	

	switch(ul_reason_for_call){
		case DLL_PROCESS_ATTACH:
			EZLOGGERSTREAM << "DLL_PROCESS_ATTACH" << std::endl;
			break; 
		case DLL_THREAD_ATTACH:
			EZLOGGERSTREAM << "DLL_THREAD_ATTACH" << std::endl;		
			break; 
		case DLL_THREAD_DETACH:
			EZLOGGERSTREAM << "DLL_THREAD_DETACH" << std::endl;
			break; 
		case DLL_PROCESS_DETACH:
			EZLOGGERSTREAM << "DLL_PROCESS_DETACH" << std::endl;
			break;
	}

	return TRUE;

}